package lzm.condition;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

public class WindowsCondition implements Condition {

    protected final Log logger = LogFactory.getLog(getClass());

    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
        String[] beanDefinitionNames = beanFactory.getBeanDefinitionNames();
        for(String s : beanDefinitionNames) {
            logger.info("WindowsCondition获取当前已注册的类"+ s);
        }


        BeanDefinitionRegistry registry = context.getRegistry();
        String[] beanDefinitionNames1 = registry.getBeanDefinitionNames();
        for(String b : beanDefinitionNames1) {
            logger.info("WindowsCondition->BeanDefinitionRegistry获取当前已注册的类"+ b);
        }
        return context.getEnvironment().getProperty("os.name").contains("Windows");
    }
}
